<%--
  Created by IntelliJ IDEA.
  User: Root404
  Date: 2022/7/12
  Time: 9:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style>
        h1{
            color: red;
        }
    </style>
</head>
<body>
<h1>欢迎来到主界面</h1>
<table border="4">
<tr>
    <th>id</th>
    <th>name</th>
    <th>sex</th>
    <th>hobby</th>
    <th>操作</th>
</tr>
    <c:forEach items="${list}" var="user" varStatus="status">
<tr <c:if test="${status.index%2==0}">style="background-color: green" </c:if> >
    <td>${user.id}</td>
    <td>${user.name}</td>
    <td>${user.sex==1?"男":"女"}</td>
    <td>${user.hobby}</td>
    <td>
        <a href="${pageContext.request.contextPath}/ServleUser?op=delete&id=${user.id}"><input type="button" value="删除" class="bt1"></a>
        <a href="${pageContext.request.contextPath}/ServleUser?op=update1&id=${user.id}"><input type="button" value="修改" ></a>
        <input type="button" value="异步删除" class="bt2">
    </td>
</tr>
    </c:forEach>

    </table>
<a href="${pageContext.request.contextPath}/jstlnc/add.jsp"><input type="button" id="add" value="增加"></a>
<h1>${isdelete}</h1>
<h1>${isupdate}</h1>
<h1>${isadd}</h1>
<script src="../js/jquery.js"></script>
<script>
    //异步删除
    $(".bt2").click(function () {
        //js内侧那id
        //alert("xxx");
         var thisbt=$(this);
       var id=  thisbt.parents("tr").children("td").eq(0).html();
        $.get("${pageContext.request.contextPath}/ServleUser?op=deleteajax&id="+id,function (data) {
                if(data=="yes"){
                    thisbt.parents("tr").remove();
                }else{
                    alert("删除失败");
                }
        });
    });



    $(".bt1").click(function () {
        alert("xxx");
            if(confirm("确定删除吗？")){
                return true;
            }else{
                return false;
            }
    });
</script>
</body>
</html>
